﻿using System.Security.Principal;

namespace Sidvall.Web.Security
{
	public class PrincipalProvider : Sidvall.Security.IPrincipalProvider
	{
		#region Public Members

		#region CurrentPrincipal

		public IPrincipal CurrentPrincipal
		{
			get
			{
				if (System.Web.HttpContext.Current != null)
					return System.Web.HttpContext.Current.User;
				return System.Threading.Thread.CurrentPrincipal;
			}
			set
			{
				System.Threading.Thread.CurrentPrincipal = value;
				if (System.Web.HttpContext.Current != null)
					System.Web.HttpContext.Current.User = value;
			}
		}

		#endregion

		#region SetThreadPrincipal

		public void SetThreadPrincipal(IPrincipal principal)
		{
		}

		#endregion
		#region ToString

		public override string ToString()
		{
			return "PrincipalProvider - System.Web.HttpContext.Current.User or Thread.CurrentPrincipal";
		}

		#endregion

		#endregion
	}
}
